<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加规则</title>
    {% load static %}
    {% csrf_token %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

   <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
                <div class="layui-inline layui-col-md6">
                    <label class="layui-form-label">业务类型:</label>
                    <div class="layui-input-block" id="type" name="type">

                    </div>
                </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">前缀<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="rule_perfix" placeholder="请输入业务类型前缀！" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">年份<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="rule_year" id="rule_year" placeholder="请选择年份" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">生成位数<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <select name="rule_suffix" lay-verify="required">
                    <option value=""></option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                </select>
            </div>
        </div>
        </div>

        <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" placeholder="请输入备注内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script>
     layui.config({
        base: '/static/lib/layui/lay/tree_select/'
    }).use(["form", "okUtils", "form", "tree", "okLayer","laydate"], function () {

        let $ = layui.$;
        let form = layui.form;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        let tree = layui.tree;
        let util = layui.util;
        let laydate = layui.laydate;
        okLoading.close();
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
         laydate.render({
                elem: '#rule_year',
                type:'date',
                format:'yyyy',
                trigger:'click'
            })
        form.on("submit(add)",function (data) {
            okUtils.ajax("{% url 'business:rules_insert' %}","post",data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });

    });
</script>
<script>
    var demo3 = xmSelect.render({
        el: '#type',
        name:'type',
        radio: true,
        tips: '选择一种业务类型，可搜索业务类型！',
        filterable: true,
        clickClose: true,
        layVerify: 'required',
        layVerType: 'msg',
        tree: {
            show: true,
            strict: true,
        },
        prop: {
            name: 'type_name',
            value: 'id',
        },
        toolbar: {show: true},
        data: []
    })
    $.ajax({
        url: "{% url 'business:type_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo3.update({
                data: node.data,
                autoRow: true,
                iconfont: {
                    parent: 'hidden',
                }
            })
        },
        error: function () {
        }
    });
</script>
</body>
</html>
